package com.intellij.licensecommon.data;

import com.intellij.licensecommon.util.a;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;


public class i {
    private final BigInteger a;
    private final BigInteger b;
    private final BigInteger c;
    private int d;

    public i(BigInteger paramBigInteger1, BigInteger paramBigInteger2) {
        this(paramBigInteger1, paramBigInteger2, 36);
    }

    public i(BigInteger paramBigInteger1, BigInteger paramBigInteger2, int paramInt) {
        this.c = paramBigInteger2;
        this.b = paramBigInteger1;

        int i = paramBigInteger2.bitLength();
        int j = (int) Math.ceil(i / Math.log(paramInt) * Math.log(2.0D));
        if (j % 5 != 0) {
            j = (j / 5 + 1) * 5;
        }
        this.d = j;
        this.a = new BigInteger(Integer.toString(paramInt));
    }

    public byte[] a(String paramString) throws a {
        try {
            ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
            BigInteger localBigInteger1 = BigInteger.ZERO;
            int i = 0;
            for (int j = 0; j < paramString.length(); j++) {
                char c1 = paramString.charAt(j);
                if ((c1 != ' ') && (c1 != '\t') && (c1 != '\n') && (c1 != '-')) {
                    localBigInteger1 = localBigInteger1.multiply(this.a).add(a(c1));
                    i++;
                    if (i == this.d) {
                        BigInteger localBigInteger2 = localBigInteger1.modPow(this.b, this.c);
                        localByteArrayOutputStream.write(localBigInteger2.toByteArray());
                        localBigInteger1 = BigInteger.ZERO;
                        i = 0;
                    }
                }
            }
            if (i != 0) {
                throw new a();
            }
            localByteArrayOutputStream.close();
            return localByteArrayOutputStream.toByteArray();
        } catch (IOException localIOException) {
        }
        return new byte[0];
    }

    private static BigInteger a(char paramChar)
            throws a {
        int i;
        if (('0' <= paramChar) && (paramChar <= '9')) {
            i = paramChar - '0';
        } else if (('A' <= paramChar) && (paramChar <= 'Z')) {
            i = paramChar - 'A' + 10;
        } else if (('a' <= paramChar) && (paramChar <= 'z')) {
            i = paramChar - 'a' + 36;
        } else if (('!' <= paramChar) && (paramChar <= ')')) {
            i = paramChar - '!' + 62;
        } else {
            throw new a();
        }
        return BigInteger.valueOf(i);
    }

    public String b(String paramString)
            throws a {
        try {
            return new String(a(paramString), "UTF-8");
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
        }
        return "";
    }

    public Map<String, String> c(String paramString) throws a {
        HashMap localHashMap = new HashMap();
        String str1 = b(paramString);
        StringTokenizer localStringTokenizer = new StringTokenizer(str1, "\n", false);
        while (localStringTokenizer.hasMoreTokens()) {
            String str2 = localStringTokenizer.nextToken();
            String str3 = localStringTokenizer.nextToken();
            localHashMap.put(str2, str3);
        }
        return localHashMap;
    }
}
